<!--  -->
<template>
    <div style="padding-bottom: 42px">
        <van-form>
          <section-header :sectionTitle="'售中售后阶段项目预定级维度：'" />
          <van-field readonly required name="incomeAmount" :value="fromdata.incomeAmount" label="项目合同收入金额(万元):"
                     label-width="12em" />
          <van-field readonly required name="regionId" :value="fromdata.regionId" label="客户等级:"
                     label-width="5em" />
          <van-field readonly required name="deliverComplex" :value="fromdata.deliverComplex" label="项目交付复杂度:" label-width="8em" >
            <template #button>
              <van-button size="small" native-type="button" type="primary" @click="getITList">打分</van-button>
            </template>
          </van-field>
          <van-field readonly required name="complexItNrm" :value="fromdata.complexItNrm" label="自研收入占比:"
                     label-width="7em" />
          <van-field readonly required name="autonomousImplemention" :value="fromdata.autonomousImplemention" label="是否自主实施:"
                     label-width="7em" />
          <van-field readonly required name="autonomousImplementionType" :value="fromdata.autonomousImplementionType" label="项目自主实施类型:"
                     label-width="9em" />
          <van-field v-if="fromdata.autonomousImplemention == '是'" readonly required name="autImplementScope" :value="fromdata.autImplementScope" label="自主实施范围：" label-width="7em"
                     :right-icon="'arrow'" @click="showUpAndDownPop = true"
                     placeholder="请选择自主实施范围" :rules="[{ required: true, message: '' }]"/>
          <van-popup v-model='showUpAndDownPop' round position="bottom" get-container="body" >
            <van-picker
                show-toolbar
                title="请选择"
                @cancel="showUpAndDownPop = false"
                :columns="UpAndDownPopColumns"
                @confirm="UpAndDownPopConfirm"/>
          </van-popup>
          <van-field readonly required name="selfPercent" :value="fromdata.selfPercent" label="自有业务占比:"
                     label-width="7em" />
          <section-header :sectionTitle="'售中售后阶段项目预定级评分：'" />
          <van-field readonly required name="onProjectGradeFinal" :value="fromdata.onProjectGradeFinal" label="售中售后阶段项目预定级评分:"
                     label-width="14em" >
            <template #button>
              <van-button size="small" native-type="button" type="primary" @click="getITGrade">评定</van-button>
            </template>
          </van-field>
          <div class="footer">
            <van-button block type="info" native-type="submit" @click="onSubmit"
                        style="display: inline-block; width: 100%; border: 0px solid #60a9ec">确定</van-button>
          </div>
        </van-form>
    </div>
</template>
<script>

import { mapGetters } from "vuex";
import { Dialog, Notify, Toast } from "vant";

import util from "@/assets/js/public";

import { getSrqrRequest,
} from "@/api/dictapi";
import SectionHeader from "@/views/sztdzj/sztdzjDetail/section-header.vue";


export default {
  components: {SectionHeader},
    data() {
        return {
          params: this.$route.query,
          fromdata: {},
          mFromdata: {},
          showUpAndDownPop:false,
          UpAndDownPopColumns:['项目整体自主实施', '项目部分自主实施'],
        };
    },

    computed: {
        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),
    },

    //生命周期--创建完成
    created() {
      this.fromdata = this.params.fromdata
      this.mFromdata = this.params.mFromdata
    },

    //生命周期--挂载完成
    mounted() {
    },

    activated() {
      if (localStorage.getItem('itListValue') != '{}' && localStorage.getItem('itListNumber')) {
        this.fromdata.deliverComplex = JSON.parse(localStorage.getItem('itListNumber'))
        this.fromdata.autonomousImplementionType = JSON.parse(localStorage.getItem('itListValue'))
        if (JSON.parse(localStorage.getItem('itListIsZiZhu'))=="1"){
          this.fromdata.autonomousImplemention = "是"
        }else {
          this.fromdata.autonomousImplemention = "否"
        }
        localStorage.setItem('itListNumber', '{}')
        localStorage.setItem('itListValue', '{}')
        localStorage.setItem('itListIsZiZhu', '{}')
      }
    },
    //方法调用
    methods: {
      UpAndDownPopConfirm(value) {
        this.showUpAndDownPop = false
        this.fromdata.autImplementScope = value
      },
      getITList(){
        console.log("点击选择框后"+JSON.stringify(this.mFromdata.itCtOrder))
        this.$router.push(
            {
              name: 'getitlist',
              query: {
                itOrder: this.mFromdata.itCtOrder.itOrder,
              }
            })
      },
      getITGrade() {
        var number=this.fromdata.complexItNrm.slice(0,1)
        if (Number(number)<5&&this.fromdata.autonomousImplementionType.includes("自主应用")){
          Dialog.confirm({ title: "提示", message: "自研收入占比≤5%，“项目自主类型字段”是否取消选择“自主应用”？" })
              .then(() => {
                this.fromdata.autonomousImplementionType = this.fromdata.autonomousImplementionType.slice(0, -5);
                getSrqrRequest('decisionMaking$api$onSaleProjectGrade',
                    Object.assign({
                          kv: {
                            "source": 'MOBILE',
                            "currentUserCode": util.encrypt(this.user.userName),
                            "complexItNrm": this.fromdata.complexItNrm,
                            "deliverComplex": this.fromdata.deliverComplex,
                            "incomeAmount": this.fromdata.incomeAmount,
                            "regionId": this.fromdata.regionId,
                            "selfPercent": this.fromdata.selfPercent,
                          },
                          body: {
                            "complexItNrm": this.fromdata.complexItNrm,
                            "deliverComplex": this.fromdata.deliverComplex,
                            "incomeAmount": this.fromdata.incomeAmount,
                            "regionId": this.fromdata.regionId,
                            "selfPercent": this.fromdata.selfPercent,
                          }
                        }
                    ))
                    .then((result) => {
                      Toast.clear();
                      if (!result.data) {
                        this.onError(result);
                        return;
                      }
                      if (result.data.data) {
                        this.fromdata.onProjectGradeFinal=result.data.data.onProjectGrade
                      }
                    })
              })
              .catch(() => { });
        }else {
          getSrqrRequest('decisionMaking$api$onSaleProjectGrade',
              Object.assign({
                    kv: {
                      "source": 'MOBILE',
                      "currentUserCode": util.encrypt(this.user.userName),
                      "complexItNrm": this.fromdata.complexItNrm,
                      "deliverComplex": this.fromdata.deliverComplex,
                      "incomeAmount": this.fromdata.incomeAmount,
                      "regionId": this.fromdata.regionId,
                      "selfPercent": this.fromdata.selfPercent,
                    },
                    body: {
                      "complexItNrm": this.fromdata.complexItNrm,
                      "deliverComplex": this.fromdata.deliverComplex,
                      "incomeAmount": this.fromdata.incomeAmount,
                      "regionId": this.fromdata.regionId,
                      "selfPercent": this.fromdata.selfPercent,
                    }
                  }
              ))
              .then((result) => {
                Toast.clear();
                if (!result.data) {
                  this.onError(result);
                  return;
                }
                if (result.data.data) {
                  this.fromdata.onProjectGradeFinal=result.data.data.onProjectGrade
                }
              })
        }
      },
      onSubmit() {
        localStorage.setItem('xmdjType', JSON.stringify(this.fromdata.onProjectGradeFinal))
        this.$router.back(-1)
      },
    },
};
</script>

<style scoped>
/* @import url();*/
</style>